import sys
import math
import typing
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets
from EnemySmallMoving import Small_Moving
from FollowSmallEnemy import FollowSmallEnemy
from BigEnemy import BigEnemy
from EnemyBullet import EnemyBullet

class EnemySet:
    def __init__(self, scene):
        self.SetSpeed = 0
        self.SetRotata = 0
        self.position = QPointF(0, 0)
        self.EnemyList = []
        self.scene = scene
        self.CallTime = 0

    def setOneSmallEnemy(self, speed, EnemyRotate,StartX,StartY):
        self.position = QPointF(StartX,StartY)
        if self.CallTime==0:
            self.EnemyList.append(Small_Moving(self.scene))
            self.CallTime = 1
        for Enemy in self.EnemyList:
            Enemy.speed = speed
            Enemy.setRotation(EnemyRotate)  # 设置角度
            Enemy.setVisible(True)
            Enemy.setPos(self.position)
        

        

    # 用来产生小人
    def setSmallEnemy(self, speed, EnemyRotate, StartX, StartY):
        if self.CallTime==0:
            for i in range(5):  # 初始化5个Enemy
                self.EnemyList.append(Small_Moving(self.scene))
            self.CallTime = 1
        self.SetSpeed = speed
        n = 0  # 记录在集合中的状态
        for self.Enemy in self.EnemyList:
            # if语句实现十字形排列
            if n == 0:
                self.position = QPointF(StartX, StartY)  # 设置position即EnemyList[0]的在scene的位置
            elif n == 1:
                #mapToScene(x,y)函数将Item在scene上的坐标向前增加x单位，向垂直方向增加y个单位
                self.position = QPointF(self.EnemyList[0].mapToScene(70,0))
            elif n == 2:
                self.position = QPointF(self.EnemyList[0].mapToScene(70,70))
            elif n == 3:
                self.position = QPointF(self.EnemyList[0].mapToScene(70,-70))
            else:
                self.position = QPointF(self.EnemyList[0].mapToScene(140,0))
            self.Enemy.speed = speed
            self.Enemy.setRotation(EnemyRotate)  # 设置角度
            self.Enemy.setVisible(True)
            self.Enemy.setPos(self.position)
            n += 1
    
    def SetFollowEnemy(self, speed, EnemyRotate, StartX, StartY): #设置跟踪的小人
        self.position = QPointF(StartX, StartY)
        if self.CallTime == 0:
            self.EnemyList.append(FollowSmallEnemy(self.scene))
            self.CallTime = 1
        for self.Enemy in self.EnemyList:
            self.Enemy.speed = speed
            self.Enemy.setRotation(EnemyRotate)  # 设置角度
            self.Enemy.setVisible(True)
            self.Enemy.setPos(self.position)

    def setBigEnemy(self, speed, EnemyRotate, StartX, StartY):
        self.position = QPointF(StartX, StartY)
        if self.CallTime == 0:
            self.EnemyList.append(BigEnemy(self.scene))
            self.CallTime = 1
        for Enemy in self.EnemyList:
            Enemy.speed = speed
            Enemy.setStartRotate(EnemyRotate) #设置起始角度
            Enemy.setVisible(True)
            Enemy.setPos(self.position)
    
    def setEnemyBullet(self, speed, EnemyRotate, StartX, StartY):
        self.position = QPointF(StartX, StartY)
        if self.CallTime == 0:
            self.EnemyList.append(EnemyBullet(self.scene))
            self.CallTime = 1
        for Enemy in self.EnemyList:
            Enemy.speed = speed
            Enemy.setRotation(EnemyRotate)  # 设置角度
            Enemy.setVisible(True)
            Enemy.setPos(self.position)